<template>
  <el-dialog
    style="overflow: hidden"
    v-model="visible"
    :title="title"
    width="50%"
    class="notice-dialog"
    @close="closeHandle"
    @close-click-modal="closeHandle"
  >
    <div class="big-box">
      <el-form ref="formRef" :model="form" :rules="rules" label-width="100px">
        <el-row :gutter="30">
            <el-col :span="12" >
                <el-form-item label="计划名称" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="草稿" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="年度" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="开始时间" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="结束时间" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="填报单位" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="操作人" prop="option"  >
                    <el-select v-model="form.option" placeholder="请选择" style="width: 100%">
                        <el-option label="选项1" value="option1"></el-option>
                        <el-option label="选项2" value="option2"></el-option>
                        <el-option label="选项3" value="option3"></el-option>
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="24">
                <el-form-item label="填报说明" prop="option"  >
                    <el-input v-model="form.option" :rows="6" type="textarea" placeholder="Please input" />
                </el-form-item>
            </el-col>
            <el-col :span="24">
              <el-form-item prop="fileList" label="附件"  required>
                <el-upload
                    class="upload-demo"
                    drag
                    action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
                    multiple
                    :before-upload="beforeUpload"
                    style="width:100%"
                    v-model:file-list="form.fileList"
                >
                    <img src="@/assets/images/management/upload-icon.png" alt="" srcset="">
                    <div class="el-upload__text">
                    只能上传后缀为.doc、.docx、.txt、.pdf格式的文件
                    </div>
                    <el-button type="primary">点击上传</el-button>
                </el-upload>
            </el-form-item>
            </el-col>
        </el-row>
      </el-form>
    </div>
    <template #footer>
      <el-row>
        <el-col :span="24" align="end">
          <el-button @click="closeHandle">取消</el-button>
          <el-button type="primary" @click="saveHandle"> 保存 </el-button>
        </el-col>
      </el-row>
    </template>
  </el-dialog>
</template>
<script setup>
const props =  defineProps({
  rowData: {
    type: Object,
    default: () => {},
  },
});
const title = ref('');
const visible = ref(false);
const open = () => {
  visible.value = true;
};
watch(() => visible.value, () => {
  console.log('弹框打开：', props.rowData);
  if (props.rowData) {
    title.value = '编辑';
  } else {
    title.value = '新增';
  }
});

defineExpose({
  open,
});

function closeHandle() {
  formRef.value.resetFields();
  visible.value = false;
}
const emit = defineEmits(['addAfterValue']);
const formRef = ref(null); // 创建 ref 对象

const form = ref({
  option: '',
});
const rules = ref({
  fileList: [{ required: true, message: '请选择文件', trigger: 'change' }],
  option: [{ required: true, message: '请选择下拉框选项', trigger: 'change' }],
});
const saveHandle = () => {
  formRef.value.validate((valid) => {
    // 使用 formRef.value
    if (valid) {
      // 表单验证通过，提交表单的逻辑
      console.log('表单验证通过');
      formRef.value.resetFields();
      emit('addAfterValue', false);
    } else {
      // 表单验证不通过，做相应处理
      console.log('表单验证不通过');
      return false;
    }
  });
};
</script>
    <style lang="scss" scoped>
img {
  vertical-align: middle;
  height: 20px;
  width: 20px;
  margin-right: 10px;
}
::v-deep .el-empty__image img {
  height: 40% !important;
  width: 40% !important;
}
.search-box {
  width: 93%;
  margin: auto;
  padding: 10px;
  .search-contain {
    margin-left: 10px;
    .el-button {
      margin: 10px 0 0 0;
    }
    ul {
      li {
        font-size: 12px;
        font-family: Source Han Sans CN-Regular, Source Han Sans CN;
        font-weight: 400;
        color: #50565d;
        line-height: 17px;
        margin: 10px 0;
        input {
          vertical-align: middle;
          margin-right: 15px;
        }
      }
    }
  }
}
.left-small-box {
  height: 27vh;
  overflow: auto;
  .contain1 {
    .el-row {
      background: none;
      border: 1px dashed #dbddde;
      margin: 20px 10px 0 20px;
      color: #25292c;
      cursor: context-menu;
      .el-col {
        margin-bottom: 0;
        padding: 8px;
        .el-icon {
          color: red;
          cursor: pointer;
        }
      }
    }
  }
  .el-row {
    background: #2e72ef;
    border-radius: 4px 4px 4px 4px;
    margin: 20px 10px 0 20px;
    color: #ffffff;
    cursor: pointer;
    .el-col {
      margin-bottom: 0;
      padding: 8px;
      .el-icon {
        cursor: pointer;
      }
    }
  }
}
.el-card.is-always-shadow {
  border: 1px solid #e8e7ea !important;
  height: 30vh;
}
.right-big-box {
  height: 60.9vh !important;
  .right-big-contain {
    height: 57vh;
    overflow: auto;
    .right-small-contain {
      height: 23vh !important;
      overflow: auto;
      .el-row {
        border: 1px dashed #dbddde;
        margin: 20px 10px 0 20px;
        .el-col {
          margin-bottom: 0;
          padding: 8px;
          .el-icon {
            color: red;
          }
        }
      }
    }
  }
}
.small-box {
  margin: 15px 0 0 16px;
}
.el-card__header {
  height: 40px;
  background-color: #f5f7fb !important;
  border: 1px solid #e8e7ea;
  padding: 10px !important;
}
.card-header {
  line-height: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}
.add-people-box {
  margin-left: 20px;
  .el-select {
    margin: 5px 10px 30px 0;
    width: 40%;
  }
  .add-people-btn {
    display: inline-block;
    float: right;
    margin-right: 20px;
    margin-top: 5px;
  }
}
.text-add-btn {
  color: #48a2ff;
  cursor: pointer;
  margin-right: 10px;
}
.text-del-btn {
  color: red;
  cursor: pointer;
}
.text-cancel-btn {
  color: #606266;
  cursor: pointer;
}
</style>
